package ejb.entities;

import java.io.Serializable;

import javax.persistence.*;

import ejb.dto.VoloDTO;

/**
 * The persistent class for the flights database table.
 * 
 */
@Entity
@Table(name = "flights")
@NamedQueries({
		@NamedQuery(name = "Flight.findAll", query = "SELECT f FROM Flight f"),
		@NamedQuery(name = "Flight.findByDatesAndCities", query = "SELECT f FROM Flight f  WHERE f.basicproduct.startdate = :dataInizio AND f.basicproduct.enddate = :dataFine AND f.departure LIKE :cittaPartenza AND f.arrival LIKE :cittaArrivo"),
		@NamedQuery(name = "Flight.findByDatesAndArrivalCity", query = "SELECT f FROM Flight f  WHERE f.basicproduct.startdate = :dataInizio AND f.basicproduct.enddate = :dataFine AND f.arrival LIKE :cittaArrivo"),
		@NamedQuery(name = "Flight.findByDates", query = "SELECT f FROM Flight f  WHERE f.basicproduct.startdate = :dataInizio  AND f.basicproduct.enddate = :dataFine"), })
public class Flight implements Serializable {
	private static final long serialVersionUID = 1L;

	public static final String FIND_ALL = "Flight.findAll";
	public static final String FIND_DATES_CITIES = "Flight.findByDatesAndCities";
	public static final String FIND_DATES_ARRIVAL_CITY = "Flight.findByDatesAndArrivalCity";
	public static final String FIND_DATES = "Flight.findByDates";

	@Id
	@GeneratedValue(strategy = GenerationType.TABLE)
	private int flightsid;

	private String arrival;

	private String company;

	private String departure;

	private String model;

	// bi-directional one-to-one association to Basicproduct
	@OneToOne
	@PrimaryKeyJoinColumn(name = "flightsid") // ReadOnly
	private Basicproduct basicproduct;

	public Flight() {
	}

	public Flight(VoloDTO voloDTO) {
		this.arrival = voloDTO.getCitta_arrivo();
		this.departure = voloDTO.getCitta_partenza();
		this.company = voloDTO.getCompagnia();
		this.model = voloDTO.getAereo();
	}

	public String getArrival() {
		return this.arrival;
	}

	public void setArrival(String arrival) {
		this.arrival = arrival;
	}

	public String getCompany() {
		return this.company;
	}

	public void setCompany(String company) {
		this.company = company;
	}

	public String getDeparture() {
		return this.departure;
	}

	public void setDeparture(String departure) {
		this.departure = departure;
	}

	public String getModel() {
		return this.model;
	}

	public void setModel(String model) {
		this.model = model;
	}


	
	public int getFlightId()
	{
		return flightsid;
	}
	public void setFlightId( int id )
	{
		this.flightsid = id;
	}

	public Basicproduct getBasicproduct() {
		return this.basicproduct;
	}

	public void setBasicproduct(Basicproduct basicproduct) {
		this.basicproduct = basicproduct;
	}

}